package com.yanqu.road.server.manger.cricket.skillhandler.attround.handler;

import com.yanqu.road.entity.cricket.helper.AddHpResult;
import com.yanqu.road.entity.enums.eSkillType;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.gameplayer.module.cricket.battle.CricketGame;
import com.yanqu.road.server.gameplayer.module.cricket.model.BattleData;
import com.yanqu.road.server.gameplayer.module.cricket.model.SkillData;
import com.yanqu.road.server.manger.cricket.skillhandler.attround.CricketSkillAttRoundStrategy;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class CricketSkill406Strategy implements CricketSkillAttRoundStrategy {
    /**
     * 技能处理-。刘备每回合普通攻击会切换武器效果，第一回合普通攻击会提升自身{0}的生命上限，第二回合普通攻击会降低对方{1}的攻击力，效果可叠加
     * @param cricketGame 本局对局对象
     * @param skillData 触发的技能
     * @param baseAttSkill 基础攻击技能
     * @param baseAttReHpResult 基础攻击结果对象
     * @param action 我方
     * @param target 对方
     * @param attackRoundBuilder 返回PB结构体
     * @return true：死亡，退出技能处理，false：继续技能处理
     */
    @Override
    public boolean skillHandle(CricketGame cricketGame, SkillData skillData, SkillData baseAttSkill, AddHpResult baseAttReHpResult, BattleData action, BattleData target, CricketProto.CricketAttackRound.Builder attackRoundBuilder, long battleFrameId) {
        //普通攻击触发 miss也一样触发
        if (baseAttSkill.getSkillEffect().getSkillType() == eSkillType.CricketBattleSkill137.getValue()){
            CricketProto.CricketBattleFrame.Builder skill406FrameBuilder = cricketGame.newBattleFrameBuilder();
            skill406FrameBuilder.setSkillId(skillData.getSkillId());
            skill406FrameBuilder.setActionUserId(action.getUserId());
            if(cricketGame.getMaxRound() % 2 == 1){     //第一回合普通攻击会提升自身{0}的生命上限
                skill406FrameBuilder.setTargetUserId(action.getUserId());
                //增加的生命上限
                long addHp = BigDecimal.valueOf(action.getMaxHp()).multiply(BigDecimal.valueOf(skillData.getSkillEffect().getP1())).divide(BigDecimal.valueOf(1000),2, RoundingMode.DOWN).longValue();

                action.addMapHp(addHp);
                //剩余的血量增加 策划说不要了
//                AddHpResult addHpResult = action.addHp(addHp);

                skill406FrameBuilder.setAttack(addHp);

            }else{      //第二回合普通攻击会降低对方{1}的攻击力
                skill406FrameBuilder.setTargetUserId(target.getUserId());
                //计算扣除对方的攻击力
                long reduceAtk = BigDecimal.valueOf(target.getBaseAtk()).multiply(BigDecimal.valueOf(skillData.getSkillEffect().getP2())).divide(BigDecimal.valueOf(1000),2, RoundingMode.DOWN).longValue();
                //设置额外攻击力扣除
                target.setAddAttack(target.getAddAttack()-reduceAtk);

                skill406FrameBuilder.setAttack(-reduceAtk);

            }
            //双方属性信息
            //注入回合数据数组
            cricketGame.fillRemainHp(skill406FrameBuilder);
            attackRoundBuilder.addAttack(skill406FrameBuilder);

        }
        return false;
    }
}
